<div id="new_stage_container">
  <%= render(:partial => "shared/flash_message") %>
  <%= render :partial => "shared/config_save_actions", :locals => {:scope => {}} -%>
  <%= form_for(@stage,
               :as => :stage,
               :url => admin_stage_create_path,
               :html => {"novalidate" => "novalidate", :name => "pipeline_edit_form", :id => "pipeline_edit_form",
                         :method => "POST",
                         :onsubmit => "return AjaxForm.jquery_ajax_submit(this);",
                         :class => "popup_form"}) do |f| %>
    <%= md5_field %>
    <%= hidden_field_tag :pipeline_digest, @pipeline_digest %>
    <%= hidden_field_tag :pipeline_group_name, @pipeline_group_name %>
    <%= hidden_field_tag :pipeline_name, @pipeline.name %>
    <input type="hidden" name="current_tab" value="stages"/>

    <div class="form_content">
      <%= render :partial => "admin/shared/global_errors.html", :locals => {:scope => {}} -%>
      <h3>Stage Information</h3>

      <div class="fieldset">
        <div class="form_item required">
          <%= label_tag stage_name_id = random_dom_id("stage_name_"), required_label_text('Stage Name') %>
          <%= f.text_field com.thoughtworks.go.config.StageConfig::NAME, :class => "form_input", :id => stage_name_id -%>
          <%= error_message_on(@stage, "name", :css_class => "form_error") %>
        </div>
        <div class="form_item checkbox_row">
          <label>Trigger Type:</label>
          <span class="stage_approval contextual_help has_go_tip_right" title="'On Success' option will automatically schedule the stage after the preceding stage completes successfully. The 'Manual' option will require a user to manually trigger the stage. For the first stage in a pipeline, setting type to 'on success' is the same as checking 'Automatic Pipeline Scheduling' on the pipeline config.">&nbsp;</span>
          <%= f.fields_for com.thoughtworks.go.config.StageConfig::APPROVAL, @stage.approval do |approval| %>
            <div class="checkbox_row">
              <%= approval.radio_button com.thoughtworks.go.config.Approval::TYPE, com.thoughtworks.go.config.Approval::SUCCESS, :id => "auto" %>
              <label for="auto">On Success</label>
            </div>

            <div class="checkbox_row">
              <%= approval.radio_button com.thoughtworks.go.config.Approval::TYPE, com.thoughtworks.go.config.Approval::MANUAL, :id => "manual" %>
              <label for="manual">Manual</label>
            </div>


            <%= error_message_on(@stage.getApproval(), "type", :css_class => "form_error") %>

            <div id="div_allow_on_success">
              <%= approval.check_box "allowOnlyOnSuccess", {}, "true", "false" %>
              <label for="stage_approval_allowOnlyOnSuccess">Allow Only On Success</label>

              <span class="stage_approval_allowOnlyOnSuccess contextual_help has_go_tip_right" title="Only allow stage to be scheduled if the previous stage run is successful.">&nbsp;</span>
            </div>

          <% end %>
        </div>
        <%= render :partial => "shared/form_required_message.html" %>
      </div>

      <h3>Initial Job and Task</h3>

      <div class="instructions">You can add more jobs and tasks to this stage once the stage has been created.</div>
      <div class="fieldset has_nested_fieldset">
        <% @stage.getJobs().each do |job| -%>
          <%= f.fields_for com.thoughtworks.go.config.StageConfig::JOBS, job, :index => "" do |job_form| %>
            <div class="form_item required">
              <%= label_tag job_name_id = random_dom_id("job_name_"), required_label_text('Job Name') %>
              <%= job_form.text_field(com.thoughtworks.go.config.JobConfig::NAME, :id => job_name_id) %>
              <%= error_message_on(job, com.thoughtworks.go.config.JobConfig::NAME, :css_class => "form_error") %>
            </div>
            <%= render :partial => "admin/shared/job_tasks.html", :locals => {:scope => {:job => job, :job_form => job_form}} -%>
          <% end %>
        <%- end -%>
      </div>
    </div>
    <%= render :partial => 'shared/convert_tool_tips.html', :locals => {:scope => {}} %>
    <%= render :partial => "shared/form_buttons.html", :locals => {:scope => {:submit_label => "SAVE"}} %>
  <% end %>

</div>
